package spindles.api.domain;

import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE;

import org.apache.commons.lang.Validate;

import spindles.api.util.Util;

import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.SecondaryKey;

@Entity
public class User extends DomainObject {
	
	/**
	 * 
	 */
	private static transient final long serialVersionUID = -906027125431996690L;

	private static final User DEFAULT = 
		new User("admin", "admin", Role.ADMIN, "Default user.");
	
	public static final String DEFAULT_USERNAME = "admin";
	
	private String firstName;
	
	private String lastName;
	
	@SecondaryKey(relate=ONE_TO_ONE)
	private String userName;
	
	private String password;
	
	private String email;
	
	private String comments;
	
	private Role role;
	
	
	public User(String username, String password, Role role, String comments){
		setUserName(username);
		setPassword(password);
		setRole(role);
		setComments(comments);
	}
	
	private User(){};
	
	public static User getDefaultUser(){
		return DEFAULT;
	}
	
	public User(String username, String password, Role role){
		this(username, password, role, "");
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		Validate.isTrue(!Util.isEmpty(userName), "Username cannot by empty");
		this.userName = userName;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}	

}
